﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

using System.Data;
using DBA.Data;

namespace DBA.Bll
{
    public class BaseCodeDDL
    {
        public static DataTable getList(string tabeName)
        {
            string strSelect = "select * from " + tabeName;
            DataTable dt = null;
            Data.ADO.DataAccessLibrary da = CommonQuery.DataAccessLibrary;
            dt = da.ExecuteFillDataTable(strSelect);
            return dt;

        }

        public static void DdlInit(DropDownList ddl, string tableName)
        {
            DataTable dt = getList(tableName);

            if (ddl != null)
            {
                ddl.Items.Clear();
                ddl.Items.Add(new ListItem("—请选择—", "-1"));
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ddl.Items.Add(new ListItem(dt.Rows[i][1].ToString(), dt.Rows[i][0].ToString()));
                }

                ddl.DataBind();
            }
        }

        public static string ConvertTime(DateTime time)
        {
            string rtnTime = "";
            if (time.ToString("yyyy") != "0001")
            {
                rtnTime = time.ToString("yyyy-MM-dd");
            }
            return rtnTime;
        }
    }
}
